package com.qtummatrix.service.impl;

import com.qtummatrix.dao.SaveMoudleDao;
import com.qtummatrix.entity.QuestionsEntity;
import com.qtummatrix.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * create by Gongshiyong  2019-12-07 11:31
 */
@Service("questionBankeService")
public class QuestionBankServiceImpl implements QuestionBankService {

    @Autowired
    @Qualifier("saveMoudleDao")
    private SaveMoudleDao saveMoudleDao;

    @Override
    public String addQuestion(QuestionsEntity questionsEntity) {
        String content = questionsEntity.getContent();
        if (questionsEntity.getId() != 0) {
            saveMoudleDao.addQuestions(questionsEntity);
            return "保存成功！";
        } else {
            QuestionsEntity questionsEntity1 = saveMoudleDao.get_QuestionbyContent(content);
            if (questionsEntity1 != null) {
                return "问题内容重复，添加失败！";
            } else {
                saveMoudleDao.addQuestions(questionsEntity);
                return "添加成功！";
            }
        }

    }

    @Override
    public List<QuestionsEntity> getQuestions(int scopeid, int typeid, String content, int n) {

        List<QuestionsEntity> list = saveMoudleDao.get_Question(scopeid, typeid, content, n);

        return list;
    }

    @Override
    public int get_sumpage(int scopeid, int typeid, String content) {
        double sum = saveMoudleDao.get_sumpage(scopeid, typeid, content);
        int sumpage = (int) Math.ceil(sum / 11);
        System.out.println(sumpage);
        return sumpage;
    }

    @Override
    public void delQuestions(int id) {
        saveMoudleDao.del_questionsfromBank(id);
        saveMoudleDao.del_questionsfromMoudel(id);
    }
}
